#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

// OpenJudge NOI 8470
// This solution gets wrong answer. I don't know where is going wrong.

struct Frag {
    std::string str;
    std::vector<std::vector<int> >
        matches;  // suffix from ith character matches fragment j

    Frag(const std::string &str) : str(str), matches(str.length() + 1) {}
};

std::vector<Frag> frags;

void search(int curLen, int lastIdx, int nSearched, int &minLen,
            std::vector<bool> &searched) {
    // All fragments are searched
    if (nSearched == frags.size()) {
        minLen = std::min(minLen, curLen);
        return;
    }

    // Not less than minimum distance
    if (curLen >= minLen)
        return;

    // Try to find next fragment to join
    Frag &frag = frags[lastIdx];
    std::string &srcStr = frag.str;
    for (int sb = 0; sb <= srcStr.length(); sb++) {
        for (int j = 0; j < frag.matches[sb].size(); j++) {
            // Skip searched target
            int ti = frag.matches[sb][j];
            if (searched[ti])
                continue;

            // Compute new length
            std::string &tgtStr = frags[ti].str;
            int dLen = tgtStr.length() + sb - srcStr.length();

            // Search next
            searched[ti] = true;
            search(curLen + dLen, ti, nSearched + 1, minLen, searched);
            searched[ti] = false;
        }
    }

    return;
}

void solve() {
    // Handle one fragment
    if (frags.size() == 1) {
        int len = frags[0].str.length();
        printf("%d\n", len);
        return;
    }

    // Match suffix with prefixes of other fragments
    for (int si = 0; si < frags.size(); si++) {
        Frag &srcFrag = frags[si];
        std::string &srcStr = srcFrag.str;
        for (int ti = 0; ti < frags.size(); ti++) {
            if (ti == si) continue;  // do not match with self

            // Concatenate source with target is okay
            srcFrag.matches[srcStr.length()].push_back(ti);

            // Match suffixes of source with prefixes of target
            std::string &tgtStr = frags[ti].str;
            for (int sb = 0; sb < srcStr.length(); sb++) {
                bool matches = true;
                int suffixLen = srcStr.length() - sb;
                for (int off = 0; off < suffixLen; off++) {
                    int sp = sb + off;
                    if (off >= tgtStr.length())
                        matches = false;  // suffix longer than target string
                    if (srcStr[sp] != tgtStr[off])
                        matches = false;  // not a prefix of target
                }
                if (matches) srcFrag.matches[sb].push_back(ti);
            }
        }
    }

    // Depth-first search all possible sequences
    std::string current;
    std::vector<bool> searched(frags.size(), false);
    int minLen = INT32_MAX;
    for (int i = 0; i < frags.size(); i++) {
        current = frags[i].str;
        searched[i] = true;
        search(current.length(), i, 1, minLen, searched);
        searched[i] = false;
    }
    printf("%d\n", minLen);

    return;
}

int main() {
    int T;
    scanf("%d", &T);
    for (int i = 0; i < T; i++) {
        // Read fragments
        int N;
        scanf("%d", &N);
        frags = std::vector<Frag>();
        frags.reserve(N);
        for (int j = 0; j < N; j++) {
            std::string str;
            std::cin >> str;
            frags.push_back(Frag(str));
        }

        // Solve the problem
        solve();
    }

    return 0;
}